<template>
	<div>
		<el-form ref="form" :rules="rules" :model="form" label-width="130px">
			<el-form-item label="项目名称" prop="name">
				<el-input v-model="form.name"></el-input>
			</el-form-item>
			<el-form-item label="项目描述" prop="description">
				<el-input type="textarea" v-model="form.description"></el-input>
			</el-form-item>
			<el-form-item label="团队" prop="teamName">
				<el-select v-model="form.teamName" placeholder="请选择">
					<el-option v-for="item in teamOptions" :key="item.id" :label="item.name" :value="item.name">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="指派人" prop="principal">
				<el-select v-model="form.principal" placeholder="请选择">
					<el-option v-for="item in principals" :key="item.relaname" :label="item.relaname" :value="item.relaname">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="项目人数" prop="number">
				<el-input v-model="form.number" style="width: 100px;"></el-input>
			</el-form-item>
			<el-form-item label="项目阶段" prop="stage">
				<el-input v-model="form.stage" disabled=""></el-input>
			</el-form-item>
			<el-form-item label="创建人" prop="creator">
				<!--如果是创建项目，就是自己默认自己；修改项目默认不能添加  -->
				<el-input v-model="form.creator"></el-input>
			</el-form-item>
			<el-form-item label="QA负责人" prop="owner">
				<!--身份是QA的里面选择  -->
				<el-select v-model="form.owner" placeholder="请选择">
					<el-option v-for="item in owners" :key="item.relaname" :label="item.relaname" :value="item.relaname">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="计划开始时间" prop="etime">
				<el-date-picker v-model="form.stime" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" clearable
				 style="width: 100%" type="datetime"></el-date-picker>
			</el-form-item>
			<el-form-item label="计划结束时间" prop="etime">
				<el-date-picker v-model="form.etime" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" clearable
				 style="width: 100%" type="datetime"></el-date-picker>
			</el-form-item>
			<el-form-item label="状态" prop="status">
				<el-select v-model="form.status" placeholder="请选择">
					<el-option label="未开始" value="0"></el-option>
					<el-option label="已关闭" value="1"></el-option>
					<el-option label="正在进行中" value="2"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" plain @click="save">保存数据</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>
<script>
	import axios from '../../utils/axiosutils.js'
	export default {
		name: 'RoleEdit',
		props: ['editid'],
		data() {
			return {
				teamOptions: '',
				principals: '',
				owners: '',
				form: {
					id: '',
					name: '',
					description: '',
					teamName: '',
					principal: '',
					number: '',
					stage: '',
					creator: '',
					owner: '',
					stime: '',
					etime: '',
					status: ''
				},
				rules: {
					name: [{
						required: true,
						message: '项目名不能为空',
						trigger: 'blur'
					}, {
						min: 1,
						max: 50,
						message: '长度在 1 到 50 个字符',
						trigger: 'blur'
					}]
				}
			}
		},
		created() {
			axios.get("/team/list", resp => {
				this.teamOptions = resp.obj.records
			})
			axios.post("/project/owners", resp => {
				this.owners = resp.obj
			})
			if (this.editid) {
				axios.get('/project/getById', response => {
					this.form = response.obj
				}, {
					id: this.editid
				});
			}
		},
		methods: {
			save: function() {
				axios.post('/project/save', resp => {
					this.$emit('update:show', false);
					this.$emit('getData');
				}, this.form);
			}
		},
		watch: {
			"form.teamName": function(newName, oldName) {
				axios.post("/project/principals", resp => {
					this.principals = resp.obj
				}, {
					teamName: newName
				})
			}
		}
	}
</script>
<style>
</style>
